package com.ys.shop.db;

import com.ys.shop.util.MyUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MySqlDBImp extends IDB{
    private Connection conn;
    private String Driver;
    private String URL;
    private String USER;
    private String PASS;
    List<String> list=new ArrayList<String>();
    //构造方法   修饰符  +  方法名（与类名相同）   +  参数  +  异常
    public MySqlDBImp(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Map<String,String> map=MyUtil.readXML("db-config.xml");
            Driver=map.get("Driver");
            URL=map.get("Url");
            USER=map.get("User");
            PASS=map.get("Pass");
            conn=DriverManager.getConnection(URL,USER,PASS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public Connection getConn() throws SQLException {
        return conn;
    }

    @Override
    public void closegetConn() throws SQLException {
        if(conn!=null&&!conn.isClosed()){
            conn.close();
        }
    }

    public static void main(String[] args) {
        MySqlDBImp mysqlDBImp=new MySqlDBImp();
        try {
            mysqlDBImp.getConn().isClosed();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
